 <!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>{$Think.config.site.title} - 商品管理</title>

    <meta name="keywords" content="{$Think.config.site.keywords}">

    <link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/animate.min.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/style.min.css?v=4.0.0" rel="stylesheet">
    <link href="{$Think.config.site.common_resource_url}js/chosen/chosen.css" rel="stylesheet" type="text/css"/>
</head>
<style>
#listtable .fa{
	cursor:pointer;
	/*color:#1ab394;*/
	margin-right:1em;
}
th .tag{font-size: 12px; color: #e66c6c; font-weight: normal;}
.ibox-title .tag{font-size: 12px; color: #e66c6c; font-weight: normal; display: inline-block; margin-left: 20px;}
.specval-hide{display: none;}

.brand-tag,.supplier-tag{
    display: inline-block;
    padding: 0px 6px;
    color: #fff;
    /*border: 1px solid #f00;*/
    border-radius: 10px;
    background-color: rgb(0, 170, 238);
}
.supplier-tag{    background-color: rgb(34, 204, 119);}

.td-big-btop{border-top: 2px solid #999 !important;}

.input-group select{width: 100%}
</style>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
      <div class="row">
            <div class="col-sm-4">
                <div id="nestable-menu">
                	<button type="button" class="btn btn-white btn-sm" onclick="window.history.go(-1)">返回</button>
                	<a href='{:url("selectgoods",["supplierid"=>$supplier["supplier_id"]],false)}' type="button" class="btn btn-primary btn-sm "><i class="fa fa-plus"></i> 添加商品</a>
                    <button type="button" class="btn btn-white btn-sm openall">展开 / 收起</button>
                </div>
            </div>
      </div>
      <div class="row">
          <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>商品列表 【{$supplier.supplier_name} {$supplier.remark}】</h5>
                        <span class="tag"></span>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                          	<div class="col-sm-12">
                                <div class="input-group pull-right">
                                <form action="{:url('index')}" method="get" enctype="application/x-www-form-urlencoded">
                                
                                <input type="hidden" name="supplierid" value="{$supplier.supplier_id}">
                                <div class="input-group pull-right">
                                    <input type="text" placeholder="请输入关键词" class="input-sm form-control" value="{$Think.get.keywords ?? ''}" name="keywords">
                                    <span class="input-group-btn">
                                        <button type="submit" class="btn btn-sm btn-primary"> 搜索</button> </span>
                                </div>

                                <div class="input-group pull-right" style="margin-right: 10px; width: 200px;">
                                    <select class="input-sm form-control chosen-select" name="cate_id">
                                        <option value="0">商品分类</option>
                                        {volist name="catelist" id="v"}
                                        <option {if($Think.get.cate_id == $v['cate_id'])} selected="selected" {/if} value="{$v.cate_id}">{$v.fullname}</option>
                                        {/volist}
                                    </select>
                                </div>
                                </form>
                                </div>
                            </div>
                            
                        </div>
                        <div class="table-responsive">
                            <table class="table" id="listtable">
                                <thead>
                                    <tr>
                                        <!-- <th width="30"><input name="checkall" id="checkall"  type="checkbox" class="i-checks" value="1"></th> -->
                                        <th width="100">商品图片</th>
                                        <th width="">商品名称<span class="tag">（点击展开）</span></th>
                                        <th width="150">价格<span class="tag">（双击修改）</span></th>
                                        <th width="150">上下架</th>
                                        <th width="100">售罄</th>
                                        <th width="150">销量</th>
                                        <th width="200">操作</th>
                                    </tr>
                                </thead>
                                <tbody>

                                	{volist name="list" id="vo"}
                                    <tr data-id="{$vo.goods_id}" data-type="goods" data-specval_id='' style="background-color: #f9f9f9">
                                        <!-- <td class="td-big-btop">
                                            <input name="ids[]"  type="checkbox" class="i-checks" value="{$vo.goods_id}">
                                        </td> -->
                                        <td class="td-big-btop"><img src="{$vo.picture}" width="30" height="30" class="preview" href="{$vo.picture}" title="{$vo.goods_name}"></td>
                                        <td class="goodsname td-big-btop">{$vo.goods_name} <span class="brand-tag">{$vo.brand_name}</span> </td>
                                        <td class="td-big-btop">{$vo.min_price}-{$vo.max_price}</td>
                                      	<td class="td-big-btop">
                                      	
                                        </td>
                                        <td class="td-big-btop">
                                        
                                        </td>
                                        <td class="td-big-btop">{$vo.sales}</td>
                                        <td class="td-big-btop">
                                        	<button class="btn btn-primary fa fa-edit editGoods"> 编辑</button>
	                                        <i class="fa fa-trash-o"> 删除</i>
                                        </td>
                                    </tr>
                                    {volist name="vo['specval']" id="voo"}
                                    <tr data-id="{$vo.goods_id}"  data-type="specval" data-specval_id="{$voo.specval_id}" class="tr-specval specval-{$vo.goods_id} specval-hide {$voo.supplier_id}">
                                        <!-- <td>
                                            <input name="ids[]"  type="hidden" class="i-checks" value="{$vo.goods_id}">
                                        </td> -->

                                        <td colspan="2"><!-- {$vo.goods_name} -->【{$voo.specval_name}】<span class="supplier-tag">{$voo.supplier_name}</span></td>
                                        <td><div class="cutprice">{$voo['price']}</div></td>
                                        <td>
                                        {switch name="voo.status"}
                                            {case value="0"}<button type="button" class="btn btn-default btn-xs btn-status">已下架</button>{/case}
                                            {case value="1"}<button type="button" class="btn btn-primary btn-xs btn-status">已上架</button>{/case}
                                        {/switch}
                                        </td>
                                        <td>
                                        {switch name="voo.sellout"}
                                            {case value="0"}<button type="button" class="btn btn-primary btn-xs btn-sellout">否</button>{/case}
                                            {case value="1"}<button type="button" class="btn btn-default btn-xs btn-sellout">是</button>{/case}
                                        {/switch}
                                        </td>
                                        <td>{$voo.sales}</td>
                                        <td>
                                            <button class="btn btn-primary fa fa-edit editGoods"> 编辑</button>
                                            <i class="fa fa-trash-o"> 删除</i>
                                        </td>
                                    </tr>
                                    {/volist}
                                   {/volist}

                                </tbody>
                            </table>
                        </div>
                        <div>{$list->render()}</div>
                    </div>
                </div>
            </div>

        </div>
    </div>

    <script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
    <script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.5"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/peity/jquery.peity.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/iCheck/icheck.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/layer/layer.js"></script>
    <script src="{$Think.config.site.common_resource_url}js/majax.js"></script>
    <script src="{$Think.config.site.common_resource_url}js/jedit.js"></script>
    <script src="{$Think.config.site.resource_url}js/jquery.imagePreview.1.0.js"></script>
    <script type="text/javascript" src="{$Think.config.site.common_resource_url}js/chosen/chosen.jquery.js"></script>
</body>

</html>
<script>



$('.goodsname').click(function(){
    var id=$(this).closest('tr').data('id');
    $('.specval-'+id).toggleClass('specval-hide');
})

$('.openall').click(function(){
    $('.tr-specval').toggleClass('specval-hide');
})

var layer_font='';
$(document).ready(function() {
	$("select").chosen({no_results_text: "没有找到：",width:'200px'});

	$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
    $("img.preview").preview();
	//全选
	$("#checkall").bind("ifChecked",function(){
		$("input[name='ids[]']").iCheck("check");
	});
	//取消全选
	$("#checkall").bind("ifUnchecked",function(){
		$("input[name='ids[]']").iCheck("uncheck");
	});
	//顶部按钮
    $("#nestable-menu").on("click",
    function(e) {
        var target = $(e.target),
        action = target.data("action");
		//保存排序
    });

	
	//上下架
	$("#listtable").on("click",".btn-status",function(){
		var self = this;
		var $tr = $(self).closest("tr");
		var id = $tr.data("id"),specval_id=$tr.data("specval_id");
		var status = $(self).hasClass("btn-primary") ? 0 : 1;
        var type = $tr.data('type');
        if (type=='goods') {
            majax('{:url("goodsState")}',{goods_id:id,status:status},function(d){
                if (d.code>0) {
                    if (d.data['status']>0) {
                        $(self).removeClass("btn-default").addClass("btn-primary").html("已上架");
                    }else{
                        $(self).removeClass("btn-primary").addClass("btn-default").html("已下架");
                    }
                }else{
                    layer.msg(d.msg);
                }
            })
        }else if(type=='specval'){
            majax('{:url("specvalState")}',{goods_id:id,specval_id:specval_id,status:status},function(d){
                if (d.code>0) {
                    if (d.data['status']>0) {
                        $('[data-id='+id+'][data-type="goods"]').find('.btn-status').removeClass("btn-default").addClass("btn-primary").html("已上架");
                        $(self).removeClass("btn-default").addClass("btn-primary").html("已上架");
                    }else{
                        $(self).removeClass("btn-primary").addClass("btn-default").html("已下架");
                    }
                }else{
                    layer.msg(d.msg);
                }
            })
        }
	})

    //售罄
    $("#listtable").on("click",".btn-sellout",function(){
        var self = this;
        var $tr = $(self).closest("tr");
        var id = $tr.data("id"),specval_id=$tr.data("specval_id");
        var status = $(self).hasClass("btn-primary") ? 1 : 0;
        var type = $tr.data('type');
        if (type=='goods') {
            majax('{:url("goodsState")}',{goods_id:id,sellout:status},function(d){
                if (d.code>0) {
                    if (d.data['status']<=0) {
                        $(self).removeClass("btn-default").addClass("btn-primary").html("否");
                    }else{
                        $(self).removeClass("btn-primary").addClass("btn-default").html("是");
                    }
                }else{
                    layer.msg(d.msg);
                }
            })
        }else if(type=='specval'){
            majax('{:url("specvalState")}',{goods_id:id,specval_id:specval_id,sellout:status},function(d){
                if (d.code>0) {
                    if (d.data['status']<=0) {
                        $('[data-id='+id+'][data-type="goods"]').find('.btn-sellout').removeClass("btn-default").addClass("btn-primary").html("否");
                        $(self).removeClass("btn-default").addClass("btn-primary").html("否");
                    }else{
                        $(self).removeClass("btn-primary").addClass("btn-default").html("是");
                    }
                }else{
                    layer.msg(d.msg);
                }
            })
        }
    })

    $('.editGoods').click(function(){
        var goodsid = $(this).closest('tr').data('id');
        layer_font = layer.open({
            type: 2,
            title: '添加商品',
            shadeClose: true,
            shade: 0.8,
            area: ['900px', '90%'],
            content: '{:url("addgoods",["supplierid"=>$supplier["supplier_id"]],null)}/goodsid/'+goodsid, //iframe的url
        });
    })


	//删除按钮注册
	$("#listtable").on("click",".fa-trash-o",function(){
		var $tr = $(this).closest("tr");
		var id = $tr.data("id");
        var type = $tr.data('type');
        if (type=='goods') {
            layer.confirm('删除该商品及规格？', {
                btn: ['确定删除','不删除'], //按钮
                shade: false //不显示遮罩
            }, function(){
                //确定删除
                var ids = [];
                $('tr[data-type="specval"][data-id="'+id+'"]').each(function(){
                    ids.push($(this).data('specval_id'));
                });
                majax('{:url("delspecval")}',{ids:ids.join(',')},function(d){
                    if (d.code>0) {
                        layer.msg('删除成功', {icon: 1},function(){
                            $('tr[data-type="specval"][data-id="'+id+'"]').each(function(){
                                $(this).remove();
                            });
                            $tr.remove();
                        });
                        
                    }else{
                        layer.msg(d.msg, {icon: 5});
                    }
                })
            },
            function(){
                
            });
        }else if (type="specval") {
            layer.confirm('删除该规格？', {
                btn: ['确定删除','不删除'], //按钮
                shade: false //不显示遮罩
            }, function(){
                //确定删除
                majax('{:url("delspecval")}',{ids:$tr.data("specval_id")},function(d){
                    if (d.code>0) {
                        layer.msg('删除成功', {icon: 1},function(){
                            $tr.remove();
                        });
                        
                    }else{
                        layer.msg(d.msg, {icon: 5});
                    }
                })
            },
            function(){
                
            });
        }
	});
	
});	

  function editSuccess(d){
        layer.close(layer_font);
        layer.msg(d.msg,{},function(){
            window.location.reload(true);
        });
    }
</script>